<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/13
 * Time: 22:07
 */
namespace app\model;


use think\facade\Db;
use think\Model;

class CleaningPoint extends Model
{

    private function _getOutListField()
    {
        return [
            'cp_id' => 'cleaningPointId',
            'cp_name' => 'cleaningPointName',
            'cp_floor' => 'cleaningPointFloor',
            'cp_orgid' => 'orgid',
            'cp_qrcode' => 'qrcode',
            'cp_check_qrcode' => 'checkQrcode',
            'cp_status' => 'status',
            'cp_create_time' => 'createtime'
        ];
    }
    public function addOneCleaningPoint($data)
    {
        $data['cp_create_time'] = time();
        return Db::table('cleaning_point')->insertGetId($data);
    }

    public function getPointInfoById($id,$field = '')
    {
        $field = $field ? $field : self::_getOutListField();
        return Db::table('cleaning_point')->where(['cp_id'=>$id])->field($field)->find();
    }

    public function updatePointInfoByWhere($where,$data)
    {
        $data['cp_update_time'] = time();
        return Db::table('cleaning_point')->where($where)->update($data);
    }

    public function getPointListByWhere($where = '', $field = '')
    {
        $field = $field ?: self::_getOutListField();
        $list = Db::table('cleaning_point')
            ->where($where)
            ->field($field)
            ->select();
        return $list;
    }
    public function getPointListByCondition($where = '', $order = 'cp_id desc', $field = '')
    {
        $field = $field ?: self::_getOutListField();
        $list = Db::table('cleaning_point')
            ->where($where)
            ->field($field)
            ->order($order)
            ->paginate(input('param.pageSize'))
            ->render();

        return $list;
    }

}